package com.example.carpro.utils

import android.content.Context
import android.widget.Toast
import com.blankj.utilcode.util.GsonUtils
import com.example.carpro.MyApplication
import java.util.*


fun String.showToast() {
    Toast.makeText(MyApplication.context, this, Toast.LENGTH_SHORT).show()
}

fun Int.showToast() {
    Toast.makeText(MyApplication.context, this, Toast.LENGTH_SHORT).show()
}

// 简单的计算
fun Calendar.getLunarDate(): String {
    val month = this.get(Calendar.MONTH)
    val day = this.get(Calendar.DATE)
    val lunarMonths = arrayOf(
        "正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月",
        "十月", "十一月", "十二月"
    )

    val lunarDays = arrayOf(
        "初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十",
        "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十",
        "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十"
    )
    return "${lunarMonths[month]}${lunarDays[day]}"
}


inline fun <reified T>  transForData(context: Context, jsonFileName: String): T {
    val jsonString = context.assets.open("${jsonFileName}.json").bufferedReader().use { it.readText() }
    return GsonUtils.fromJson(jsonString, T::class.java)
}





